package com.kuhyygy.broadcast;

import com.kuhyygy.activity.LoginActivity;
import com.kuhyygy.uitl.ActivityCollector;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.view.WindowManager;

public class ForceOffLineBroadcast extends BroadcastReceiver {

	@Override
	public void onReceive(final Context ctx, Intent arg1) {
		AlertDialog.Builder ad = new AlertDialog.Builder(ctx);
		ad.setCancelable(false);
		ad.setTitle("warning");
		ad.setMessage("you are forced to be off line");
		ad.setPositiveButton("OK", new OnClickListener() {
			
			@Override
			public void onClick(DialogInterface arg0, int arg1) {
				ActivityCollector.removeAll();
				Intent i = new Intent(ctx, LoginActivity.class);
				i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				ctx.startActivity(i);
			}
		});
		AlertDialog dia = ad.create();
		dia.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
		dia.show();
	}

}
